package ewms.controller;

import java.util.List;
import java.util.Arrays;

import ewms.bo.EwmsTransferWarehouseDetailAddBo;
import ewms.bo.EwmsTransferWarehouseDetailEditBo;
import ewms.bo.EwmsTransferWarehouseDetailQueryBo;
import ewms.vo.transfer_warehouse.EwmsTransferWarehouseDetailVo;
import ewms.service.IEwmsTransferWarehouseDetailService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import ewms.common.annotation.RepeatSubmit;
import ewms.common.annotation.Log;
import ewms.common.core.controller.BaseController;
import ewms.common.core.domain.AjaxResult;
import ewms.common.enums.BusinessType;
import ewms.common.utils.poi.ExcelUtil;
import ewms.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 危废转库明细Controller
 *
 * @author zhaoxiaochun
 * @date 2022-02-15
 */
@Api(value = "危废转库明细控制器", tags = {"危废转库明细管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/business/transferWarehouseDetail")
public class EwmsTransferWarehouseDetailController extends BaseController {

    private final IEwmsTransferWarehouseDetailService iEwmsTransferWarehouseDetailService;

    /**
     * 查询危废转库明细列表
     */
    @ApiOperation("查询危废转库明细列表")
    @PreAuthorize("@ss.hasPermi('business:transferWarehouseDetail:list')")
    @GetMapping("/list")
    public TableDataInfo<EwmsTransferWarehouseDetailVo> list(@Validated EwmsTransferWarehouseDetailQueryBo bo) {
        return iEwmsTransferWarehouseDetailService.queryPageList(bo);
    }

    /**
     * 导出危废转库明细列表
     */
    @ApiOperation("导出危废转库明细列表")
    @PreAuthorize("@ss.hasPermi('business:transferWarehouseDetail:export')")
    @Log(title = "危废转库明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<EwmsTransferWarehouseDetailVo> export(@Validated EwmsTransferWarehouseDetailQueryBo bo) {
        List<EwmsTransferWarehouseDetailVo> list = iEwmsTransferWarehouseDetailService.queryList(bo);
        ExcelUtil<EwmsTransferWarehouseDetailVo> util = new ExcelUtil<EwmsTransferWarehouseDetailVo>(EwmsTransferWarehouseDetailVo.class);
        return util.exportExcel(list, "危废转库明细");
    }

    /**
     * 获取危废转库明细详细信息
     */
    @ApiOperation("获取危废转库明细详细信息")
    @PreAuthorize("@ss.hasPermi('business:transferWarehouseDetail:query')")
    @GetMapping("/{transferWarehouseDetailId}")
    public AjaxResult<EwmsTransferWarehouseDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("transferWarehouseDetailId") Long transferWarehouseDetailId) {
        return AjaxResult.success(iEwmsTransferWarehouseDetailService.queryById(transferWarehouseDetailId));
    }

    /**
     * 新增危废转库明细
     */
    @ApiOperation("新增危废转库明细")
    @PreAuthorize("@ss.hasPermi('business:transferWarehouseDetail:add')")
    @Log(title = "危废转库明细", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody EwmsTransferWarehouseDetailAddBo bo) {
        return toAjax(iEwmsTransferWarehouseDetailService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改危废转库明细
     */
    @ApiOperation("修改危废转库明细")
    @PreAuthorize("@ss.hasPermi('business:transferWarehouseDetail:edit')")
    @Log(title = "危废转库明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody EwmsTransferWarehouseDetailEditBo bo) {
        return toAjax(iEwmsTransferWarehouseDetailService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除危废转库明细
     */
    @ApiOperation("删除危废转库明细")
    @PreAuthorize("@ss.hasPermi('business:transferWarehouseDetail:remove')")
    @Log(title = "危废转库明细" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{transferWarehouseDetailIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] transferWarehouseDetailIds) {
        return toAjax(iEwmsTransferWarehouseDetailService.deleteWithValidByIds(Arrays.asList(transferWarehouseDetailIds), true) ? 1 : 0);
    }
}
